<template>
  <u-swipe-action @click.native.stop="toDetail">
    <u-swipe-action-item :options="options1" @click.stop="cancelRepair">
      <view class="house-item">
        <view class="title">
          <view class="left">
            {{repairItem.houseInfo}}
          </view>
          <view class="right">
            <view class="success" v-if="repairItem.status === 2">
              上门中
            </view>
            <view class="waiting" v-if="repairItem.status === 1">
              受理中
            </view>
            <view class="error" v-if="repairItem.status === 3">
              已完成
            </view>
            <view class="cancel" v-if="repairItem.status === 0">
              已取消
            </view>
          </view>
        </view>
        <view class="content">
          <view class="number">
            <text>报修项目</text>
            <text>{{repairItem.repairItemName}}</text>
          </view>
          <view class="name">
            <text>预约时间</text>
            <text>{{repairItem.appointment}}</text>
          </view>
          <view class="mobile">
            <text>电话号码</text>
            <text>{{repairItem.mobile}}</text>
          </view>
        </view>
      </view>
    </u-swipe-action-item>
  </u-swipe-action>
</template>

<script>
  import {
    cancelRepair
  } from '../../api/repair.js'
  export default {
    name: "repair-item",
    data() {
      return {
        isDel: true,
        options1: [{
          text: '取消',
          style: {
            backgroundColor: '#CC655E'
          }
        }]
      };
    },
    methods: {
      // 进入详情页
      toDetail() {
        if (this.isDel) {
          uni.navigateTo({
            url: '/pkg-reply/online-reply/online-reply?id=' + this.repairItem.id
          })
        }
      },
      // 取消报修
      async cancelRepair() {
        this.isDel = !this.isDel
        if (!this.isDel) {
          const res = await cancelRepair(this.repairItem.id)
          // console.log(res.code);
          if (res.code === 400) {
            return uni.showToast({
              title: '该报修无法取消',
              icon: 'error'
            })
          } else {
            uni.showToast({
              title: '取消成功',
              icon: 'success'
            })
            this.$emit('updateList')
          }
        }

      },
    },
    props: {
      repairItem: {
        type: Object,
      }
    }
  }
</script>

<style lang="scss">
  ::v-deep .house-item {
    width: 100%;
    height: 249rpx;
    border-radius: 16rpx;
    background: #FFFFFF;

    .title {
      height: 96rpx;
      border-bottom: 1rpx solid #F2F2F6;
      // padding: 0 30rpx;
      display: flex;
      justify-content: space-between;
      align-items: center;

      .left {
        font-size: 30rpx;
        color: #333;
      }

      .right {
        .success {
          width: 128rpx;
          height: 48rpx;
          color: #27AE60;
          border-radius: 10rpx;
          background: #EBF8F0;
          font-size: 24rpx;
          line-height: 48rpx;
          text-align: center;
        }

        .waiting {
          width: 104rpx;
          height: 48rpx;
          border-radius: 10rpx;
          background: #E5F0FB;
          text-align: center;
          line-height: 48rpx;
          font-size: 24rpx;
          color: #2D9CDB;
        }

        .error {
          width: 128rpx;
          height: 48rpx;
          color: #EB5757;
          border-radius: 10rpx;
          background: #FCF2ED;
          font-size: 24rpx;
          line-height: 48rpx;
          text-align: center;
        }

        .cancel {
          width: 128rpx;
          height: 48rpx;
          color: #979797;
          border-radius: 10rpx;
          background: #F2F2F6;
          font-size: 24rpx;
          line-height: 48rpx;
          text-align: center;
        }
      }
    }

    .content {
      height: 152rpx;
      padding: 24rpx 30rpx;
      box-sizing: border-box;
      display: flex;
      flex-direction: column;
      justify-content: space-between;

      view {
        display: flex;
        justify-content: space-between;
        font-size: 28rpx;

        text:nth-child(1) {
          color: #C3C3C5;
        }

        text:nth-child(2) {
          color: #686868;

        }
      }
    }
  }
</style>
